import {
  AGGREGATE,
  BETWEEN_OPERATOR,
  BINARY_OPERATOR,
  CASE,
  CAST,
  COLLATE,
  COLUMN_PARAM,
  COLUMN_REF,
  DESCRIBE_QUERY,
  EXPRESSION,
  FRAGMENT,
  FROM_CLAUSE,
  FUNCTION,
  IN_OPERATOR,
  JOIN_CLAUSE,
  LOGICAL_OPERATOR,
  NOT_BETWEEN_OPERATOR,
  ORDER_BY,
  PARAM,
  SCALAR_SUBQUERY,
  SELECT_CLAUSE,
  SELECT_QUERY,
  SET_OPERATION,
  UNARY_OPERATOR,
  UNARY_POSTFIX_OPERATOR,
  UNNEST,
  WHEN,
  WINDOW,
  WINDOW_CLAUSE,
  WINDOW_DEF,
  WINDOW_EXTENT_EXPR,
  WINDOW_FRAME,
  WINDOW_FUNCTION,
  WITH_CLAUSE
} from '../constants.js';

export const recurse: Record<string, string[]> = {
  [AGGREGATE]: ['args', 'order', 'filter'],
  [BETWEEN_OPERATOR]: ['expr', 'extent'],
  [BINARY_OPERATOR]: ['left', 'right'],
  [CASE]: ['expr', '_when', '_else'],
  [CAST]: ['expr'],
  [COLLATE]: ['expr'],
  [COLUMN_PARAM]: ['param', 'table'],
  [COLUMN_REF]: ['table'],
  [DESCRIBE_QUERY]: ['query'],
  [EXPRESSION]: ['node'],
  [FRAGMENT]: ['spans'],
  [FROM_CLAUSE]: ['expr'],
  [FUNCTION]: ['args'],
  [IN_OPERATOR]: ['expr', 'values'],
  [JOIN_CLAUSE]: ['left', 'right', 'on', 'using', 'sample'],
  [LOGICAL_OPERATOR]: ['clauses'],
  [NOT_BETWEEN_OPERATOR]: ['expr', 'extent'],
  [ORDER_BY]: ['expr'],
  [PARAM]: ['value'],
  [SCALAR_SUBQUERY]: ['subquery'],
  [SELECT_CLAUSE]: ['expr'],
  [SELECT_QUERY]: ['_with', '_select', '_from', '_where', '_sample', '_groupby', '_having', '_window', '_qualify', '_orderby'],
  [SET_OPERATION]: ['queries', '_orderby'],
  [UNARY_OPERATOR]: ['expr'],
  [UNARY_POSTFIX_OPERATOR]: ['expr'],
  [UNNEST]: ['expr'],
  [WHEN]: ['when', 'then'],
  [WINDOW]: ['func', 'def'],
  [WINDOW_CLAUSE]: ['def'],
  [WINDOW_DEF]: ['partition', 'order', 'framedef'],
  [WINDOW_EXTENT_EXPR]: ['expr'],
  [WINDOW_FRAME]: ['extent'],
  [WINDOW_FUNCTION]: ['args'],
  [WITH_CLAUSE]: ['query']
};
